package Teach;

import java.io.*;

/**
 * description:如何判断两个文件是不是同一个文件（内容一样）？
 * author:zcx
 * lenovo
 * 时间：2022.01.18.13.10
 */
public class Pj5 {
    public static void main(String[] args) {
        File f1 = new File("my.java");
        File f2 = new File("my.txt");
        try (FileInputStream fis1 = new FileInputStream(f1); FileInputStream fis2 = new FileInputStream(f2)) {
            byte[] buf1 = new byte[1024];
            byte[] buf2 = new byte[1024];
            int len1=0;
            int len2=0;
            while ((fis1.read(buf1))==fis2.read(buf2)) {
               if(new String(buf1, "UTF-8").equals(new String(buf2, "UTF-8"))){
                   System.out.println("两个文件内容相同");
               }else {
                   System.out.println("两个文件不相同");
               }
                //System.out.println(new String(buf1, "UTF-8"));
                //System.out.println(new String(buf2, "UTF-8"));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
